package com.mq.transaction;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author ytj
 * @date 2024/1/23
 */
@Component
public class Demo12Producer {
    @Resource
    private RabbitTemplate rabbitTemplate;

    @Transactional(rollbackFor = Exception.class)
    public void send(Integer id) throws Exception{
        Demo12Message demo12Message=new Demo12Message(id);
        this.rabbitTemplate.convertAndSend(Demo12Message.EXCHANGE_NAME,Demo12Message.ROUTING_KEY,demo12Message);
        System.out.println("发送消息成功");
        //10秒之后才会提交消息
        Thread.sleep(10000);
    }
}
